import numpy as np
import theano
import theano.tensor as T

state = theano.shared(np.array(0, dtype=np.float64), 'state')
# np.float64-->s
inc = T.scalar('inc', dtype=state.dtype)

# 输入为inc 更新state=state+inc
accumulator = theano.function([inc], state, updates=[(state, state + inc)])
print(accumulator(10))

# getvalue
print(state.get_value())

# setvalue
state.set_value(-1)
print(state.get_value())

# 暂时用一下，但是不更新sharedvalue
tmp_func = state * 2 + inc

# skip_shared=theano.function([inc,a],tmp_func)

# print(skip_shared(2,3))
# print(state.get_value())

a = T.scalar('a',dtype=state.dtype)
skip_shared=theano.function([inc,a],tmp_func,givens=[(state,a)])
print(skip_shared(2,112))
print(state.get_value())
